package com.cms.freemarker.service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cms.service.SubjectDataService;
import com.core.page.Pagination;

@Service("subjectDataServiceAdaptor")
public class SubjectDataServiceAdaptor {
	
	@Autowired
	private SubjectDataService subjectDataService;
	
	public List getSubjects(String idSubject) {
		return subjectDataService.getSubjects(idSubject);
	}

	public Pagination<Map> getSubjects(String idSubject, int pageNum,
			int pageSize) {
		Pagination pagination = new Pagination(pageNum, pageSize);
		return subjectDataService.getSubjects(idSubject, pagination);
	}

	public Map getSubject(String idSubject, String itemId) {
		return subjectDataService.getSubject(idSubject, itemId);
	}

	public Object getSubjectItemValue(String idSubject, String itemId,
			String itemName) {
		return subjectDataService.getSubjectItemValue(idSubject, itemId, itemName);
	}

	public int getSubjectSize(String idSubject) {
		return subjectDataService.getSubjectSize(idSubject);
	}

	public Pagination<Map> getSubjects(String idSubject, BigDecimal pageNum, BigDecimal pageSize,
			Object... paramValues) {
		Map params = fillParams(paramValues);
		Pagination pagination = new Pagination(pageNum.intValue(), pageSize.intValue());
		return subjectDataService.getSubjects(idSubject, params, pagination);
	}
	
	public List getSubjects(String idSubject, Object... paramValues) {
		Map params = fillParams(paramValues);
		return subjectDataService.getSubjects(idSubject, params);
	}

	private Map fillParams(Object[] paramValues){
		Map params = new HashMap();
		//将paramValues装入map
		for (int i = 0; i + 1 < paramValues.length; i=i+2) {
			Object key = paramValues[i];
			Object value = paramValues[i + 1];
			params.put(key, value);
		}
		return params;
	}
	
	public String getRelativePathByKey(String key){
		return subjectDataService.getRelativePathByKey(key);
	}
}
